package com.sunchp.nio.sample.block;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BlockServer {
    private ExecutorService executorService;

    public BlockServer(ExecutorService executorService) {
        this.executorService = executorService;
    }

    public void serve() {
        try {
            ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
            serverSocketChannel.socket().bind(new InetSocketAddress(8080));

            while (true) {
                SocketChannel socketChannel = serverSocketChannel.accept();
//                this.executorService.execute(new BlockHandler(socketChannel));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new BlockServer(Executors.newFixedThreadPool(4)).serve();
    }
}
